package com.bjpowernode.boss.web.Settings;

import com.bjpowernode.boss.web.interceptors.TokenInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebMvcSettings implements WebMvcConfigurer {
    @Resource
    TokenInterceptor tokenInterceptor;
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")  //可跨域的域名，可以为 * ,请求来源
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")//允许使用的请求方式
                .allowCredentials(true)   //表示是否允许浏览器发送Cookie. true:支持发送cookie
                .maxAge(3600)             //用来指定本次预检请求的有效期，单位为秒。在有效期间，不用发出另一条预检请求
                .allowedHeaders("*");     //允许跨域的请求头
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /*registry.addInterceptor(tokenInterceptor)
                .excludePathPatterns("/operator/LoginCheck");*/
    }
}
